
from whiff import whiffenv
from whiff import resolver

def calcSum(env, start_response):
    env = resolver.process_cgi(env, parse_cgi=True)
    grades = whiffenv.cgiGet(env, "grades", "0")
    result = "temporary initial value"
    gradeSplit = grades.split()
    try:
        gradeInts = [ int(g) for g in gradeSplit ]
    except:
        result = "all grades must be integers, please"
    else:
        result = sum(gradeInts)
    resultString = str(result)
    start_response('200 OK', [('Content-Type', 'text/html')])
    return [ resultString ]

__wsgi__ = calcSum
